<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ChOperationLog;
use App\CustHub\Annotation\ChPermission;
use App\CustHub\Request\RoomTagRequest;
use App\CustHub\Service\ChRoomAutoTagConfigService;
use App\CustHub\Service\ChRoomTagService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Mine\MineController;

#[Controller(prefix: "ch/roomTag")]
class RoomTagController extends MineController
{
    #[Inject]
    protected ChRoomTagService $service;

    #[Inject]
    protected ChRoomAutoTagConfigService $configService;

    #[PostMapping('tagList'),ChPermission('ch:room:tag:list')]
    public function tagList(): \Psr\Http\Message\ResponseInterface
    {
        $data = $this->service->tagList($this->request->all());
        return $this->success($data);
    }

    #[PostMapping('tagPageList')]
    public function tagPageList(): \Psr\Http\Message\ResponseInterface
    {
        $data = $this->service->tagPageList($this->request->all());
        return $this->success($data);
    }

    #[PostMapping('save'),ChPermission('ch:room:tag:save'),ChOperationLog]
    public function save(RoomTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        $data = $this->service->save($request->all());
        return $this->success(['id'=>$data]);
    }

    /**
     * 更新标签
     * @param RoomTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('update'),ChPermission('ch:room:tag:update'),ChOperationLog]
    public function update(RoomTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->update($request->input('id'),$request->all()) ? $this->success() : $this->error();
    }

    /**
     * 批量新增标签
     * @param RoomTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('batchSave'),ChPermission('ch:room:tag:batch:save'),ChOperationLog]
    public function batchSaveTag(RoomTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->batchSaveTag($request->all())  ? $this->success() : $this->error();
    }

    /**
     * 删除标签组
     * @param RoomTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delete'),ChPermission('ch:room:tag:delete'),ChOperationLog]
    public function deleteTagGroup(RoomTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->deleteTagGroup($request->all())  ? $this->success() : $this->error();
    }


    /**
     * 添加群
     * @param RoomTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('addRoom'),ChOperationLog]
    public function addRoom(RoomTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->addRoom($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 标签里删除群
     * @param RoomTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delRoom'),ChOperationLog]
    public function delRoom(RoomTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->delRoom($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 移动标签
     * @param RoomTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('moveRoom'),ChOperationLog]
    public function moveRoom(RoomTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->moveRoom($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 标签配置
     * @param RoomTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('tagConfig'),ChOperationLog]
    public function tagConfig(RoomTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->configService->getConfig($request->input('tag_id')));
    }

    /**
     * 移动标签
     * @param RoomTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('saveTagConfig'),ChOperationLog]
    public function saveTagConfig(RoomTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->configService->saveConfig($request->all()) ? $this->success() : $this->error();
    }
}